home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 136_01 / tz1.c < prev    next >
Text File  |  1980-01-01  |  23KB  |  1,176 lines

  1. /*    HEADER:  CUG136.20;
  2.     TITLE:        TZ;
  3.     VERSION:    0.29;
  4.     DATE:        3/12/1986;
  5.     DESCRIPTION:    "Twilight Zone Adventure Game (part 1)";
  6.     KEYWORDS:    game,adventure;
  7.     SYSTEM:        CP/M,MS-DOS,TOS;
  8.     FILENAME:    TZ1.C;
  9.     AUTHORS:    R. Rodman;
  10.     COMPILERS:    C/80,Aztec,Alcyon;
  11. */
  12.  
  13. /* TWILIGHT ZONE GAME
  14.  
  15.     TZ1.C - First half
  16.  
  17.     From 810717 (original assembler version) to 830125 in Z80 assembler.
  18.  
  19.     831025 rr begin conversion to C 0.10
  20.     831101 rr dictionary in room file 0.13
  21.     831104 rr add terminal file stuff 0.14
  22.     850412 rr mods for ibm 0.21
  23.     850429 rr for unbuf,use open returns int; for buf,use fopen
  24.             returns FILE (Aztec) 0.24
  25.     850430 rr try allocating buffer for Aztec 0.25
  26.     850521 rr try to fix messed-up message 0.27
  27.     860228 rr fix \n for cp/m 0.28
  28.     860311 rr split into two parts 0.29
  29.             add type to fopen
  30.     860312 rr st stuff
  31.  
  32. Version number is currently not displayed anywhere
  33.  
  34. NOTE:    The alloc() function does not work on the Atari ST.  To simplify
  35.     our lives, I don't use it.
  36.  
  37. The IBM switch is only known to work with the AZTEC compiler.
  38. */
  39.  
  40. /* #define IBM */    /* define this for IBM INT 10 screen control */
  41. #define TERMINAL    /* define this for TERMINAL.SYS */
  42.  
  43. /* #define AZTEC */    /* define this for Aztec C compiler */
  44. /* #define C80 */    /* define this for C/80 */
  45. #define DRI        /* define this for DRI C */
  46. #define ST        /* define this (and DRI?) for Atari ST */      
  47.  
  48. #ifdef C80
  49. #define DOS bdos
  50. #endif
  51.  
  52. #ifdef AZTEC
  53. #include "stdio.h"
  54. #include "fcntl.h"
  55. #define DOS bdos
  56. #endif
  57.  
  58. #ifdef DRI
  59. #include "stdio.h"
  60. #define DOS __BDOS
  61. #endif
  62.  
  63. #ifdef ST
  64. #include "osbind.h"
  65. #endif
  66.  
  67. #define BUFSIZE 30000
  68.  
  69. int cnt,i;
  70. char *room[ 256 ];            /* rooms */
  71. char *wlk_msg[ 24 ];            /* points to walker messages */
  72. char inp_buf[ 34 ];            /* input buffer */
  73. int inp_cnt = 0;            /* input buffer pointer */
  74.  
  75. #ifdef TERMINAL
  76.  
  77. #define BYTE char
  78. #define ESC '\033'
  79.  
  80. struct {                /* terminal file structure */    
  81.     BYTE width, height, defint, uselst, yfirst, method, addx, addy;
  82.     char inistr[ 8 ], clrscn[ 8 ], clreos[ 8 ], clreol[ 8 ];
  83.     char curoff[ 8 ], curon[ 8 ], curbeg[ 8 ], curmid[ 8 ];
  84.     char curend[ 8 ], hiint[ 8 ], loint[ 8 ], revvid[ 8 ];
  85.     char norvid[ 8 ], inslin[ 8 ], dellin[ 8 ];
  86. } trmbuf = {
  87. #ifdef ST
  88. /* Values for ST or Heath terminals */
  89.  
  90.     80, 24, 'H', 'Y', 'Y', '0', 32, 32,
  91.     0, 0, 0, 0, 0, 0, 0, 0,        /* inistr */
  92.     ESC, 'E', 0, 0, 0, 0, 0, 0,    /* clrscn */
  93.     ESC, 'J', 0, 0, 0, 0, 0, 0,    /* clreos */
  94.     ESC, 'K', 0, 0, 0, 0, 0, 0,    /* clreol */
  95.     ESC, 'x', '5', 0, 0, 0, 0, 0,    /* curoff */
  96.     ESC, 'y', '5', 0, 0, 0, 0, 0,    /* curon */
  97.     ESC, 'Y', 0, 0, 0, 0, 0, 0,    /* curbeg */
  98.     0, 0, 0, 0, 0, 0, 0, 0,        /* curmid */
  99.     0, 0, 0, 0, 0, 0, 0, 0,        /* curend */
  100.     0, 0, 0, 0, 0, 0, 0, 0,        /* hiint */
  101.     0, 0, 0, 0, 0, 0, 0, 0,        /* loint */
  102.     ESC, 'p', 0, 0, 0, 0, 0, 0,    /* revvid */
  103.     ESC, 'q', 0, 0, 0, 0, 0, 0,    /* norvid */
  104.     ESC, 'L', 0, 0, 0, 0, 0, 0,    /* inslin */
  105.     ESC, 'M', 0, 0, 0, 0, 0, 0    /* dellin */
  106. #endif
  107.  
  108. #ifndef ST
  109. /* Values for Televideoid terminals */
  110.  
  111.     80, 24, 'H', 'Y', 'Y', '0', 32, 32,
  112.     0, 0, 0, 0, 0, 0, 0, 0,        /* inistr */
  113.     '\032', 0, 0, 0, 0, 0, 0, 0,    /* clrscn */
  114.     ESC, 'Y', 0, 0, 0, 0, 0, 0,    /* clreos */
  115.     ESC, 'T', 0, 0, 0, 0, 0, 0,    /* clreol */
  116.     ESC, '.', '0', 0, 0, 0, 0, 0,    /* curoff */
  117.     ESC, '.', '2', 0, 0, 0, 0, 0,    /* curon */
  118.     ESC, '=', 0, 0, 0, 0, 0, 0,    /* curbeg */
  119.     0, 0, 0, 0, 0, 0, 0, 0,        /* curmid */
  120.     0, 0, 0, 0, 0, 0, 0, 0,        /* curend */
  121.     ESC, '(', 0, 0, 0, 0, 0, 0,    /* hiint */
  122.     ESC, ')', 0, 0, 0, 0, 0, 0,    /* loint */
  123.     ESC, 'G', '4', 0, 0, 0, 0, 0,    /* revvid */
  124.     ESC, 'G', '0', 0, 0, 0, 0, 0,    /* norvid */
  125.     ESC, 'R', 0, 0, 0, 0, 0, 0,    /* inslin */
  126.     ESC, 'E', 0, 0, 0, 0, 0, 0    /* dellin */
  127. #endif
  128. };
  129.  
  130. #endif
  131.  
  132. #ifdef IBM
  133. struct {
  134.     int width, height;
  135. } trmbuf = {
  136.     80, 25
  137. };
  138. #endif
  139.  
  140. /* Dictionary: words should be strung together,separated by spaces.
  141.     Only the unique part should be included.Contained in first line
  142.     of TZ.R.Every word including the last one must be followed by spaces.
  143.     Incidentally,all lines of TZ.R should be terminated only by
  144.     line feeds.*/
  145.  
  146. char *dic_ptr;
  147.  
  148. /* Controls used in messages are:
  149.     *    clear screen
  150.     ^    position cursor to message line (causes CEOL)
  151.     \    carriage return/line feed (causes CEOL)
  152.     |    position cursor to user input line (HEIGHT-2)
  153.     _    include answer here (e.g._4)
  154. */
  155.  
  156. /* The following pieces of information must be saved */
  157.  
  158. int rm_num = 0;            /* room number */
  159. int seed;            /* random seed */
  160. int wtchct = 0;            /* tv watch count */
  161. int beerct = 0;            /* drink beer count */
  162. int cratct = 0;            /* open crate count */
  163. int pushct = 0;            /* push button count */
  164. int pushfl = 0;            /* push button error flag */
  165. int answer[ 5 ] = { 0,1,2,3,4 };    /* digits of answer */
  166.  
  167. struct walker {
  168.     int inrm;        /* in room flag */
  169.     int rsel;        /* room pointer */
  170.     int dsel;        /* description selector */
  171.     int locn[ 8 ];        /* rooms walker appears at */
  172. };
  173.  
  174. /* Woman walker descriptor */
  175.  
  176. struct walker woman = {
  177.     0,0,0,
  178.     4,52,64,95,109,185,204,248 };
  179.  
  180. /* Man walker descriptor */
  181.  
  182. struct walker man = {
  183.     0,0,0,
  184.     3,49,97,105,111,144,166,175 };
  185.  
  186. /* Rod walker descriptor */
  187.  
  188. struct walker rod = {
  189.     0,0,0,
  190.     1,27,61,120,165,196,180,254 };
  191.  
  192. /* The following are not saved */
  193.  
  194. int nu_fl = 1;            /* new room flag */
  195. int curcol = 0;            /* cursor column */
  196.  
  197. int noun, verb;            /* word numbers */
  198.  
  199. char databuf[ BUFSIZE ];    /* statically allocated buffer */
  200.  
  201. extern hello();
  202. extern exbed(), pool(), echh(), busy(), call7(), call11(), sign(), book();
  203. extern opsafe(), dlcomb(), paper(), form(), blot(), seeslf(), seecow();
  204. extern mirhse(), menu(), drwatr(), excrat(), opcrat(), writing();
  205. extern inst(), buyber(), drbeer(), ridhor(), taktrn(), taknot(), plates();
  206. extern opgrat(), examtv(), wtchtv(), exhand(), push();
  207.  
  208. char xgetc();
  209.  
  210. /* Main Program */
  211.  
  212. main()
  213. {
  214.     int junk;
  215.  
  216.     term_init();        /* init terminal */
  217.  
  218.     hello();
  219.  
  220. /* initialize data */
  221.  
  222.     init_data();
  223.  
  224.     xputs( "\n\n?Dimensions out of range at address 1423" );
  225.  
  226.     junk = 0;
  227.     seed = 719;
  228.  
  229.     while( junk == 0 ) {
  230.         junk = xgetc();
  231.         seed = seed * 13;
  232.     }
  233.  
  234. /* synthesize solution from random number into answer[ 0..4 ] */
  235.  
  236.     if( seed < 0 ) seed = 0 - seed;        /* get abs value */ 
  237.  
  238.     answer[ 0 ] = seed % 5;
  239.     answer[ 1 ] = ( seed / 5 ) % 5;
  240.     answer[ 2 ] = ( seed / 25 ) % 5;
  241.     answer[ 3 ] = ( seed / 125 ) % 5;
  242.     answer[ 4 ] = ( seed / 625 ) % 5;
  243.  
  244.     while( 1 ) {
  245.         game();        /* process game */
  246.         input();    /* get input */
  247.     }
  248. }
  249.  
  250. #ifdef TERMINAL
  251.  
  252. /* --------TERMINAL FILE LOGIC-------- */
  253.  
  254. term_init()
  255. {
  256.     int t;
  257.  
  258. #ifdef C80
  259.     t = fopen( "TERMINAL.SYS","r" );
  260. #endif
  261.  
  262. #ifdef AZTEC
  263.     t = open( "TERMINAL.SYS", O_RDONLY );
  264. #endif
  265.  
  266. #ifdef DRI
  267.     t = open( "TERMINAL.SYS", 0 );
  268. #endif
  269.  
  270.     if( t == 0 ) return;    /* default to televideoid */
  271.  
  272.     read( t, &trmbuf, 128 );
  273.  
  274. #ifdef C80
  275.     fclose( t );
  276. #endif
  277.  
  278. #ifdef AZTEC
  279.     close( t );
  280. #endif
  281.  
  282. #ifdef DRI
  283.     close( t );
  284. #endif     
  285.  
  286. }
  287.  
  288. /* output a coordinate */
  289.  
  290. coord( c )
  291. int c;
  292. {
  293.     switch( trmbuf.method ) {
  294.     case 0 :
  295.     case '0' :
  296.     case 'B' :            /* binary positioning */
  297.         xputc( c ); break;
  298.     case 1 :
  299.     case '1' :
  300.     case 'A' :            /* ascii positioning */
  301.         if( c >= 100 ) {
  302.             xputc( '0' + c / 100 );
  303.             c %= 100;
  304.         }
  305.         if( c >= 10 ) {
  306.             xputc( '0' + c / 10 );
  307.             c %= 10;
  308.         }
  309.         xputc( '0' + c );
  310.     }
  311. }
  312.  
  313. /* position cursor */
  314.  
  315. goxy( x, y )
  316. int x, y;
  317. {
  318.     xputs( trmbuf.curbeg );
  319.     if( trmbuf.yfirst == 'Y' ) coord( y + trmbuf.addy );
  320.         else coord( x + trmbuf.addx );
  321.     xputs( trmbuf.curmid );
  322.     if( trmbuf.yfirst == 'Y' ) coord( x + trmbuf.addx );
  323.         else coord( y + trmbuf.addy );
  324.     xputs( trmbuf.curend );
  325. }
  326.  
  327. cls()
  328. {
  329.     xputs( trmbuf.clrscn );
  330. }
  331.  
  332. ceol()
  333. {
  334.     xputs( trmbuf.clreol );
  335. }
  336.  
  337. high()
  338. {
  339.     xputs( trmbuf.hiint );
  340. }
  341.  
  342. low()
  343. {
  344.     xputs( trmbuf.loint );
  345. }
  346.  
  347. reverse()
  348. {
  349.     xputs( trmbuf.revvid );
  350. }
  351.  
  352. normal()
  353. {
  354.     xputs( trmbuf.norvid );
  355. }
  356.  
  357. #endif        /* --------END OF TERMINAL FILE LOGIC-------- */
  358.  
  359. #ifdef IBM
  360.  
  361. /* --------IBM SCREEN LOGIC-------- */
  362.  
  363. term_init()
  364. {
  365. }
  366.  
  367. cls()
  368. {
  369.  
  370. #asm
  371.     mov    ah,0    ;subfunction - set display mode
  372.     mov    al,2    ;set mode to 80x25 bw
  373.     int    10H
  374. #endasm
  375.  
  376. }
  377.  
  378. goxy(